package
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.ui.Keyboard;
	
	internal class __EditItem extends Sprite
	{
		private var _dis:Object;
		private var _opt:__ObjectPropertyType;
		
		public function __EditItem( dis:Object, opt:__ObjectPropertyType )
		{
			super();
			_dis = dis;
			_opt = opt;
			init();
		}
		
		private function init():void
		{
			var txt:TextField = new TextField();
			txt.filters = [new GlowFilter(0,1,2,2,5)];
			txt.textColor = 0xffffff;
			txt.text = _opt.name;
			txt.width = 100;
			txt.height = txt.textHeight + 4;
			addChild( txt );
			
			txt = new TextField();
			var old:* = _dis[_opt.name];
			txt.text = String(old);
			if( _opt.canModify )
			{
				txt.border = true;
				txt.type = TextFieldType.INPUT;
				txt.addEventListener( KeyboardEvent.KEY_DOWN, onChange, false, 0, true );
			}
			txt.x = 100;
			txt.height = this.height;
			txt.width = 100;
			addChild( txt );
		}
		
		private function onChange( e:KeyboardEvent ):void
		{
			if( e.keyCode != Keyboard.ENTER ) return;
			
			var txt:TextField = e.currentTarget as TextField;
			
			var value:*;
			var old:* = _dis[_opt.name];
			if( old is Boolean )
			{
				value = Boolean(txt.text=="true");
			}
			else if( old is Number )
			{
				value = Number(txt.text);
			}
			else if( old is int )
			{
				value = int(txt.text);
			}
			else if( old is uint )
			{
				value = uint(txt.text);
			}
			else if( old is String )
			{
				value = String(txt.text);
			}
			try
			{
				_dis[_opt.name] = value;				
			}
			catch( err:Error ){};
			txt.text = value.toString();
		}
	}
}

















